package win.demonlegion.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class CustomThreadPoolExecutor {
    @Value("${thread-pool.core-pool-size}")
    private int corePoolSize;
    @Value("${thread-pool.maximum-pool-size}")
    private int maximumPoolSize;
    @Value("${thread-pool.keep-alive-time}")
    private long keepAliveTime;

    @Bean
    public ExecutorService getThreadPoolExecutor() {
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
                keepAliveTime, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>());
    }
}
